import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from "path"
import AutoImport from "unplugin-auto-import/vite"
import Components from "unplugin-vue-components/vite"
import { ElementPlusResolver } from "unplugin-vue-components/resolvers"
import viteLegacyPlugin from '@vitejs/plugin-legacy'
import postCssPxToRem from 'postcss-pxtorem'
import autoprefixer from 'autoprefixer'
// https://vitejs.dev/config/
export default defineConfig({
  base: "./",
  publicDir: "public",
  plugins: [vue(),
  AutoImport({
    resolvers: [ElementPlusResolver()],
  }),
  Components({
    resolvers: [ElementPlusResolver()]
  }),
  viteLegacyPlugin({
    targets: ["chrome 64"],
    modernPolyfills: true,
    additionalLegacyPolyfills: ["regenerator-runtime/runtime"]
  })
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  },
  // server: {
  //   port: 9000,
  //   open: true,
  //   proxy: {
  //     "/api": {
  //       target: "http://192.168.3.6:8091",
  //       changeOrigin: true,
  //       rewrite: path => path.replace(/^\/api/, "")
  //     }
  //   }
  // },
  css: {
    devSourcemap: true,
    postcss: {
      plugins: [
        postCssPxToRem({
          rootValue: 16,
          propList: ['*']
        }),
        autoprefixer({
          overrideBrowserslist: [
            "Android 4.1",
            "iOS 7.1",
            "Chrome > 31",
            "ff > 31",
            "ie >= 8"]
        })
      ]
    }
  },
  build: {
    minify: "terser",
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true
      }
    },
    target: "modules",
    assetsDir: "assets",
    outDir: "dist",
    sourcemap: false,
    chunkSizeWarningLimit: 1000,
  }
})
